<?php
// $Id$

/**
 * Controller_People 控制器
 */
class Controller_People extends Controller_Abstract
{

	function actionIndex()
	{
        // 为 $this->_view 指定的值将会传递数据到视图中
		# $this->_view['text'] = 'Hello!';
		return $this->_redirect(url("mine"));
	}
	
	function actionUser(){
		$this->_view['location'] = 'mine';
		
        //var_dump($_GET);
		if(isset($_GET['username']) && $_GET['username'] == trim($_GET['username'])){
			$username = DB::real_escape(strtolower($_GET['username']));
			$query = "select * from user where name = '$username'";
			$res = DB::query($query);
			if(DB::num_rows() < 1){
				$this->_view['username'] = '未知用户';
				$this->_view['noHaveThisUser'] = true;
				return;
			}
			while($row = $res->fetch_assoc()){
				$user_id = $row['id'];
				$this->_view['username'] = $username;
                $this->_view['nickname'] = $row['nickname'];
				$this->_view['registerTime'] = $row['register_time'];
			}
			$this->_view['haveHelper'] = true;
			
			$query = "select sec.id, name, follow_time, code
				from sec_sum, sec, sec_follow
				where sec_sum.id = sec.id and sec_follow.sec_id = sec.id
				order by follow_time desc;";
			$res = DB::query($query);
			$rows = array();
			while($row = $res->fetch_assoc()){
				$rows[] = $row;
			}
			$this->_view['rows'] = $rows;
			
			$query = "select press, id, press_time 
				from sec_press
				where user_id = $user_id
				order by view_time desc
				";
			$res = DB::query($query);
			$presses = array();
			while($row = $res->fetch_assoc()){
				$presses[] = $row;
			}
			$this->_view['ps'] = $presses;
		}else{
			return $this->actionIndex();
		}
	}
}


